package com.rao.gmall.pay.api;


import com.rao.gmall.feign.order.OrderFeignClient;
import com.rao.gmall.model.order.OrderInfo;
import com.rao.gmall.pay.service.PayService;
import com.rao.gmall.pay.vo.PayParamsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/api/payment")
@RestController
public class PayController {

    @Autowired
    PayService payService;

    @Autowired
    OrderFeignClient orderFeignClient;

//    @ResponseBody //返回json
    @GetMapping(value = "/alipay/submit/{orderId}",produces = "text/html")
    public String payment(@PathVariable("orderId") Long orderId) throws Exception {
        PayParamsVo paramsVo = new PayParamsVo();

        OrderInfo orderById = orderFeignClient.getOrderInfo(orderId);
        paramsVo.setTotal_amount(orderById.getTotalAmount().toString());
        paramsVo.setOut_trade_no(orderById.getOutTradeNo());

        paramsVo.setSubject(orderById.getConsignee()+"的订单");
        paramsVo.setBody(orderById.getOrderComment());
        //调用支付
        String result = payService.payOrder(paramsVo);
        return result;
    }
}
